package com.spyx.activity.service.impl;

import com.atyx.spyx.enums.CouponStatus;
import com.atyx.spyx.model.activity.CouponUse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spyx.activity.mapper.CouponUseMapper;
import com.spyx.activity.service.CouponUseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 优惠券领用表 服务实现类
 * </p>
 *
 * @author yhp
 * @since 2024-05-21
 */
@Service
public class CouponUseServiceImpl extends ServiceImpl<CouponUseMapper, CouponUse> implements CouponUseService {

    @Override
    public void updateCouponInfoUseStatus(Long userId, Long couponId, Long orderId) {
       //1.设置更新条件  update coupon_use set order_id=xx,coupon_status=xx,usetime=xxx where user_id=xx and couponid=xxx
        LambdaQueryWrapper<CouponUse> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CouponUse::getUserId,userId);
        wrapper.eq(CouponUse::getCouponId,couponId);
        //2.设置更新的数据
        CouponUse couponUse = new CouponUse();
        couponUse.setOrderId(orderId);
        couponUse.setCouponStatus(CouponStatus.USED);
        couponUse.setUsedTime(new Date());
        //3.更新
        baseMapper.update(couponUse,wrapper);

    }
}
